package com.jxt.myjxtmanager.ui.model;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.google.gson.Gson;
import com.jxt.myjxtmanager.entity.CourseListBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 课程安排Model类
 * Created by qm on 2017/3/9 0009.
 */
public class CourseMo {
    /**
     * 总数据
     */
    private List<CourseListBean.CourseBean> queryList;
    private final Context context;
    private OnFindAllDataListener onFindAllDevicesListener;

    private String str = "{\n" +
            "    \"code\": 1,\n" +
            "    \"error_code\": 0,\n" +
            "    \"is_msg\": 0,\n" +
            "    \"late_num\": 5,\n" +
            "    \"result\": [\n" +
            "        {\n" +
            "            \"classId\": \"100022305\",\n" +
            "            \"className\": \"一班\",\n" +
            "            \"courseTime\": \"第一节\",\n" +
            "            \"teacherOneName\": \"张老师\",\n" +
            "            \"teacherOnePhone\": \"18546532698\",\n" +
            "            \"courseContentOne\": \"班队\",\n" +
            "            \"teacherTwoName\": \"李老师\",\n" +
            "            \"teacherTwoPhone\": \"18546532698\",\n" +
            "            \"courseContentTwo\": \"数学\",\n" +
            "            \"teacherThreeName\": \"王老师\",\n" +
            "            \"teacherThreePhone\": \"18546532698\",\n" +
            "            \"courseContentThree\": \"语文\",\n" +
            "            \"teacherFourName\": \"李老师\",\n" +
            "            \"teacherFourPhone\": \"18546532698\",\n" +
            "            \"courseContentFour\": \"数学\",\n" +
            "            \"teacherFiveName\": \"王老师\",\n" +
            "            \"teacherFivePhone\": \"18546532698\",\n" +
            "            \"courseContentFive\": \"语文\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"classId\": \"100022305\",\n" +
            "            \"className\": \"一班\",\n" +
            "            \"courseTime\": \"第二节\",\n" +
            "            \"teacherOneName\": \"李老师\",\n" +
            "            \"teacherOnePhone\": \"18546532698\",\n" +
            "            \"courseContentOne\": \"数学\",\n" +
            "            \"teacherTwoName\": \"李老师\",\n" +
            "            \"teacherTwoPhone\": \"18546532698\",\n" +
            "            \"courseContentTwo\": \"数学\",\n" +
            "            \"teacherThreeName\": \"王老师\",\n" +
            "            \"teacherThreePhone\": \"18546532698\",\n" +
            "            \"courseContentThree\": \"语文\",\n" +
            "            \"teacherFourName\": \"李老师\",\n" +
            "            \"teacherFourPhone\": \"18546532698\",\n" +
            "            \"courseContentFour\": \"数学\",\n" +
            "            \"teacherFiveName\": \"王老师\",\n" +
            "            \"teacherFivePhone\": \"18546532698\",\n" +
            "            \"courseContentFive\": \"语文\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"classId\": \"100022305\",\n" +
            "            \"className\": \"一班\",\n" +
            "            \"courseTime\": \"第三节\",\n" +
            "            \"teacherOneName\": \"王老师\",\n" +
            "            \"teacherOnePhone\": \"18546532698\",\n" +
            "            \"courseContentOne\": \"语文\",\n" +
            "            \"teacherTwoName\": \"王老师\",\n" +
            "            \"teacherTwoPhone\": \"18546532698\",\n" +
            "            \"courseContentTwo\": \"语文\",\n" +
            "            \"teacherThreeName\": \"李老师\",\n" +
            "            \"teacherThreePhone\": \"18546532698\",\n" +
            "            \"courseContentThree\": \"数学\",\n" +
            "            \"teacherFourName\": \"王老师\",\n" +
            "            \"teacherFourPhone\": \"18546532698\",\n" +
            "            \"courseContentFour\": \"语文\",\n" +
            "            \"teacherFiveName\": \"李老师\",\n" +
            "            \"teacherFivePhone\": \"18546532698\",\n" +
            "            \"courseContentFive\": \"数学\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"classId\": \"100022305\",\n" +
            "            \"className\": \"一班\",\n" +
            "            \"courseTime\": \"第四节\",\n" +
            "            \"teacherOneName\": \"梅老师\",\n" +
            "            \"teacherOnePhone\": \"18546532698\",\n" +
            "            \"courseContentOne\": \"美术\",\n" +
            "            \"teacherTwoName\": \"张老师\",\n" +
            "            \"teacherTwoPhone\": \"18546532698\",\n" +
            "            \"courseContentTwo\": \"书法\",\n" +
            "            \"teacherThreeName\": \"牛老师\",\n" +
            "            \"teacherThreePhone\": \"18546532698\",\n" +
            "            \"courseContentThree\": \"体育\",\n" +
            "            \"teacherFourName\": \"民老师\",\n" +
            "            \"teacherFourPhone\": \"18546532698\",\n" +
            "            \"courseContentFour\": \"民族环境\",\n" +
            "            \"teacherFiveName\": \"牛老师\",\n" +
            "            \"teacherFivePhone\": \"18546532698\",\n" +
            "            \"courseContentFive\": \"体育\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"classId\": \"100022305\",\n" +
            "            \"className\": \"一班\",\n" +
            "            \"courseTime\": \"午休\",\n" +
            "            \"teacherOneName\": \"马阿姨\",\n" +
            "            \"teacherOnePhone\": \"18546532698\",\n" +
            "            \"courseContentOne\": \"午休\",\n" +
            "            \"teacherTwoName\": \"马阿姨\",\n" +
            "            \"teacherTwoPhone\": \"18546532698\",\n" +
            "            \"courseContentTwo\": \"午休\",\n" +
            "            \"teacherThreeName\": \"马阿姨\",\n" +
            "            \"teacherThreePhone\": \"18546532698\",\n" +
            "            \"courseContentThree\": \"午休\",\n" +
            "            \"teacherFourName\": \"马阿姨\",\n" +
            "            \"teacherFourPhone\": \"18546532698\",\n" +
            "            \"courseContentFour\": \"午休\",\n" +
            "            \"teacherFiveName\": \"马阿姨\",\n" +
            "            \"teacherFivePhone\": \"18546532698\",\n" +
            "            \"courseContentFive\": \"午休\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"classId\": \"100022305\",\n" +
            "            \"className\": \"一班\",\n" +
            "            \"courseTime\": \"第五节\",\n" +
            "            \"teacherOneName\": \"英老师\",\n" +
            "            \"teacherOnePhone\": \"18546532698\",\n" +
            "            \"courseContentOne\": \"英语\",\n" +
            "            \"teacherTwoName\": \"金老师\",\n" +
            "            \"teacherTwoPhone\": \"18546532698\",\n" +
            "            \"courseContentTwo\": \"科学\",\n" +
            "            \"teacherThreeName\": \"缪老师\",\n" +
            "            \"teacherThreePhone\": \"18546532698\",\n" +
            "            \"courseContentThree\": \"信息\",\n" +
            "            \"teacherFourName\": \"乐老师\",\n" +
            "            \"teacherFourPhone\": \"18546532698\",\n" +
            "            \"courseContentFour\": \"音乐\",\n" +
            "            \"teacherFiveName\": \"金老师\",\n" +
            "            \"teacherFivePhone\": \"18546532698\",\n" +
            "            \"courseContentFive\": \"科学\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"classId\": \"100022305\",\n" +
            "            \"className\": \"一班\",\n" +
            "            \"courseTime\": \"第六节\",\n" +
            "            \"teacherOneName\": \"英老师\",\n" +
            "            \"teacherOnePhone\": \"18546532698\",\n" +
            "            \"courseContentOne\": \"英语\",\n" +
            "            \"teacherTwoName\": \"尚老师\",\n" +
            "            \"teacherTwoPhone\": \"18546532698\",\n" +
            "            \"courseContentTwo\": \"品德\",\n" +
            "            \"teacherThreeName\": \"乐老师\",\n" +
            "            \"teacherThreePhone\": \"18546532698\",\n" +
            "            \"courseContentThree\": \"音乐\",\n" +
            "            \"teacherFourName\": \"高老师\",\n" +
            "            \"teacherFourPhone\": \"18546532698\",\n" +
            "            \"courseContentFour\": \"阅读\",\n" +
            "            \"teacherFiveName\": \"康老师\",\n" +
            "            \"teacherFivePhone\": \"18546532698\",\n" +
            "            \"courseContentFive\": \"健康\"\n" +
            "        },\n" +
            "        {\n" +
            "            \"classId\": \"100022305\",\n" +
            "            \"className\": \"一班\",\n" +
            "            \"courseTime\": \"第七节\",\n" +
            "            \"teacherOneName\": \"金老师\",\n" +
            "            \"teacherOnePhone\": \"18546532698\",\n" +
            "            \"courseContentOne\": \"科学\",\n" +
            "            \"teacherTwoName\": \"习老师\",\n" +
            "            \"teacherTwoPhone\": \"18546532698\",\n" +
            "            \"courseContentTwo\": \"自习\",\n" +
            "            \"teacherThreeName\": \"高老师\",\n" +
            "            \"teacherThreePhone\": \"18546532698\",\n" +
            "            \"courseContentThree\": \"阅读\",\n" +
            "            \"teacherFourName\": \"习老师\",\n" +
            "            \"teacherFourPhone\": \"18546532698\",\n" +
            "            \"courseContentFour\": \"自习\",\n" +
            "            \"teacherFiveName\": \"缪老师\",\n" +
            "            \"teacherFivePhone\": \"18546532698\",\n" +
            "            \"courseContentFive\": \"信息\"\n" +
            "        }\n" +
            "    ],\n" +
            "    \"msg\": null,\n" +
            "    \"success\": true,\n" +
            "    \"failed\": false,\n" +
            "    \"error\": false\n" +
            "}";

    public CourseMo(Context context) {
        this.context = context;
        queryList = new ArrayList<>();
        mGson = new Gson();
    }

    public List<CourseListBean.CourseBean> getQueryList() {
        return queryList;
    }

    public void RequestData() {

//        HttpClient.getInstance().httpCheckWorkInfo(context, new ResultCallback() {
//            @Override
//            public void onFailure(Request request, Exception e) {
//                super.onFailure(request, e);
//            }
//
//            @Override
//            public void onError(int code, String message) {
//                super.onError(code, message);
//            }
//
//            @Override
//            public void onResponse(Object response) {
//                super.onResponse(response);
//            }
//
//            @Override
//            public void onResponse(int code, String msg) {
//                super.onResponse(code, msg);
//            }
//
//            @Override
//            public void onFinish() {
//                super.onFinish();
//            }
//
//            @Override
//            public void onStart() {
//                super.onStart();
//            }
//        });

        loadData();
    }

    private Gson mGson;

    private void loadData() {
        //模拟网络加载
        Message message = new Message();
        message.arg1 = 2;
        loadDataHandler.sendMessageDelayed(message, 1000);
    }

    private Handler loadDataHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            CourseListBean mResult = mGson.fromJson(str, CourseListBean.class);
            queryList = mResult.getResult();
            onFindAllDevicesListener.onFindSuccess();
        }
    };


    public void setOnFindAllDevicesListener(OnFindAllDataListener onFindAllDevicesListener) {
        this.onFindAllDevicesListener = onFindAllDevicesListener;
    }

    /**
     * 请求监听
     */
    public interface OnFindAllDataListener {
        void onFindSuccess();

        void onFailure();

        void onError();
    }
}
